From: Matthias Clasen Date: Sat, 16 Jul 2022 12:16:37 +0000 (-0400) Subject: gtk-demo: Add a winning sound to the puzzle X-Git-Tag: archive/raspbian/4.8.3+ds-2+rpi1~3^2~81^2^2~57^2~1 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=f7811f5dc3c8909114a21f8af4a0e631290bd6dd;p=gtk4.git gtk-demo: Add a winning sound to the puzzle We should celebrate every win. --- diff --git a/demos/gtk-demo/sliding_puzzle.c b/demos/gtk-demo/sliding_puzzle.c index b65bc428fb..592fe0fde2 100644 --- a/demos/gtk-demo/sliding_puzzle.c +++ b/demos/gtk-demo/sliding_puzzle.c @@ -5,6 +5,7 @@ * small sliding puzzle game. */ +#include "config.h" #include /* Include the header for the puzzle piece */ @@ -24,6 +25,30 @@ static guint height = 3; static guint pos_x; static guint pos_y; +static void +ended (GObject *object) +{ + g_object_unref (object); +} + +static void +celebrate (gboolean win) +{ + char *path; + GtkMediaStream *stream; + + if (win) + path = g_build_filename (GTK_DATADIR, "sounds", "freedesktop", "stereo", "complete.oga", NULL); + else + path = g_build_filename (GTK_DATADIR, "sounds", "freedesktop", "stereo", "dialog-error.oga", NULL); + stream = gtk_media_file_new_for_filename (path); + gtk_media_stream_set_volume (stream, 1.0); + gtk_media_stream_play (stream); + + g_signal_connect (stream, "notify::ended", G_CALLBACK (ended), NULL); + g_free (path); +} + static gboolean move_puzzle (GtkWidget *grid, int dx, @@ -157,6 +182,8 @@ check_solved (GtkWidget *grid) picture = gtk_grid_get_child_at (GTK_GRID (grid), pos_x, pos_y); gtk_picture_set_paintable (GTK_PICTURE (picture), piece); + celebrate (TRUE); + return TRUE; }